<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
<head>
<title></title>
<base href="<%=basePath%>">
<%@ include file="/base/jsp/include.jsp"%>
<script type="text/javascript">
	var grid;
	var creditsFun = function() {
		var rows = grid.datagrid('getSelections');
		if (rows.length != 1) {
			parent.$.messager.w('请选择一条记录进行查看！');
			return;
		}
		var nickName="";
		if(rows[0].nickName!=null&&rows[0].nickName!=""){
			nickName=rows[0].nickName;
		}
		var url = sy.contextPath + '/go.do?path=user/userCreditLogList&id=' + rows[0].id;
		var dialog = parent.sy.modalDialog({
			title : '积分日志——'+nickName,
			width : 800,
			height : 620,
			url : url
		});
	};
    var delFun = function() {
        var rows = grid.datagrid('getSelections');
        if (rows.length == 0) {
            parent.$.messager.w('请选择需要删除的记录！');
            return;
        }
        parent.$.messager.confirm('询问', '您确定要删除此记录？', function(r) {
            if (r) {
                var ids = [];
                for ( var i = 0, l = rows.length; i < l; i++) {
                    var r = rows[i];
                    ids.push(r.id);
                }
                var id = ids.join(',');
                
                $.post(sy.contextPath + '/activitymessage/del.do', {
                    id : id
                }, function() {
                    rows.length = 0;//必须，否则有bug
                    grid.datagrid('reload');
                }, 'json');
            }
        });
    };
	$(function() {
		
		var menu;
		menu={
				url : sy.contextPath + '/activitymessage/list.do',
				toolbar : '#toolbar',
				singleSelect : false,
				columns : [ [ {
					width : $(this).width() * 0.06,
					title : '活动名称',
					field : 'activityName',
					align : 'center'
				},{
                    width : $(this).width() * 0.06,
                    title : '发布人',
                    field : 'nickName',
                    align : 'center',
                    formatter : function(value, row, index){
                        return '<span href="javascript:void(0);">'+row.nickName+"("+row.account+")"+'</span>';
                    }
                },{
					width : $(this).width() * 0.1,
					title : '活动类型',
					field : 'activityTypeName',
					align : 'center'
				},{
                    width : $(this).width() * 0.1,
                    title : '类型',
                    field : 'type',
                    align : 'center',
                    formatter : function(value, row, index){
                        if(row.type==0){
                        	 return  '<a href="javascript:void(0);"  style="color:red" title="发布">发布</a>';
                        }else if(row.type==1){
                        	return  '<a href="javascript:void(0);"  style="color:red" title="转载">转载</a>';
                        }
                    }
                },{
					width : $(this).width() * 0.1,
					title : '活动时间',
					field : 'activityTime',
					align : 'center',
				},{
					width : $(this).width() * 0.1,
					title : '活动地点',
					field : 'area',
					align : 'center',
				},{
					width : $(this).width() * 0.08,
					title : '嘉宾名称',
					field : 'name',
					align : 'center',
				}, {
					width : $(this).width() * 0.1,
					title : '单位',
					field : 'company',
					align : 'center',
				}, {
                    width : $(this).width() * 0.07,
                    title : '职务',
                    field : 'job',
                    align : 'center',
                }, {
                    width : $(this).width() * 0.07,
                    title : '专业领域',
                    field : 'zyly',
                    align : 'center',
                }, {
                    width : $(this).width() * 0.1,
                    title : '活动内容',
                    field : 'content',
                    align : 'center',
                    formatter : function(value, row, index){
                    	return '<a href="javascript:void(0);" title="点击查看详情" onclick="checkContent(\''+row.id+'\')">'+row.content+'</a>';
                    }
                }, {
                    width : $(this).width() * 0.1,
                    title : '图片',
                    field : 'image',
                    align : 'center',
                    formatter : function(value, row, index) {
                        if(value!=null&&value!=''){
                            return po.showImg(value,20,20);
                        }else{
                            return null;
                        }
                    }
                }, {
					width : $(this).width()*0.05,
					title : '状态',
                    field : 'isAgree',
                    align : 'center',
                    formatter : function(value, row, index) {
                        if(value == 0){
                        	return  '<a href="javascript:void(0);"  style="color:red" title="未审核">未审核</a>';
                        }else if(value == 1){
                        	return  '<a href="javascript:void(0);"  ><img src="base/images/yes.png" title="审核通过" > </img></a>';
                        }else if(value == 2){
                        	return  '<a href="javascript:void(0);"  ><img src="base/images/no.png" title="审核不通过" > </img></a>';
                        }
                    }
				},{
					width : $(this).width()*0.05,
					title : '查看所有邀请嘉宾',
                    field : 'findAll',
                    align : 'center',
                    formatter : function(value, row, index) {
                        return '<a href="javascript:void(0);" onclick="findAll(\''+row.id+'\');">查看所有邀请嘉宾</a>'
                    }
				}, {
                    width : $(this).width()*0.1,
                    title : '操作',
                    field : 'isAgrees',
                    align : 'center',
                    formatter : function(value, row, index) {
                    	if(row.isAgree == 1 || row.isAgree == 2){
                    		if(row.publishTime =='' || row.publishTime==null){
                    			return  '<a href="javascript:void(0);"  style="color:red" >已经审核过了！</a><button onclick = "tops(\''+row.isAgree+'\',\''+row.id+'\');">置顶</button>';
                			}else{
                				return  '<a href="javascript:void(0);"  style="color:red" >已经审核过了！</a><button onclick = "cancelTops(\''+row.isAgree+'\',\''+row.id+'\');">取消置顶</button>';
                			}                   		
                    	}else if(row.isAgree == 0){
                    		return '<a><button onclick="forbidden(1,\''+row.id+'\');">审核通过</button></a><a><button onclick="forbidden(2,\''+row.id+'\');">审核不通过</button></a>';
                    	}
                        
                    }
                }
				] ]
			};
		
		grid = $('#grid').datagrid(menu);
	});
	
	function forbidden(isAgree,id) {
		  if(isAgree == 1){
			parent.$.messager.confirm('询问',"确定审核通过吗？", function(r) {
				if (r) {
					var data = {
						id : id,
						isAgree : 1
					};
					SaveData(data);
				}
			});
		} else if(isAgree == 2){
			parent.$.messager.confirm('询问',"确定审核不通过吗？", function(r) {
                if (r) {
                    var data = {
                        id : id,
                        isAgree : 2
                    };
                    updateByNotAgreeReason(id);
                }
            });
		}
	}
	function SaveData(data) {
		var url = sy.contextPath + '/activitymessage/update.do';
		$.post(url, data, function() {
			grid.datagrid('reload');
		}, 'json');
	}

	function updateByNotAgreeReason(id){
        var url = sy.contextPath +'/go.do?path=activityMsg/notAgreeReason&id=' + id;
        var dialog = parent.sy.modalDialog({
            title : '审核不通过原因',
            width : 800,
            height : 620,
            url : url,
            buttons : [ {
                text : '确认',
                handler : function() {
                    dialog.find('iframe').get(0).contentWindow.submitForm(dialog, grid, parent.$);
                }
            } ]
        });
   }
	
	function checkContent(id){
		var url = sy.contextPath +'/go.do?path=activityMsg/contentDetail&id=' + id;
        var dialog = parent.sy.modalDialog({
            title : '内容',
            width : 800,
            height : 620,
            url : url,
        });
	}
	
	function tops(isAgree,id){
		if(isAgree==2){
	     	   $.messager.alert('Warning','审核未通过的不能置顶...');
	  		   return;
	     	}
		var url = sy.contextPath + '/activitymessage/top.do';
		var data={
				id: id
		}
		$.post(url, data, function() {
            grid.datagrid('reload');
        }, 'json'); 
	}
	
	function cancelTops(isAgree,id){
		   if(isAgree==2){
			   $.messager.alert('Warning','审核未通过的不能置顶...');
			   return;
		   }
	       var url = sy.contextPath + '/activitymessage/cancelTops.do';
	       var data={
	               id: id
	       }
	       $.post(url, data, function() {
	           grid.datagrid('reload');
	       }, 'json'); 
	   }
	
	function findAll(id){
		var url = sy.contextPath + '/go.do?path=activityMsg/findAll&id=' + id;
		var dialog = parent.sy.modalDialog({
            title : '查看所有人员',
            width : 800,
            height : 620,
            url : url,
        });
	}
</script>
</head>
<body class="easyui-layout" data-options="fit:true,border:false">
	<div id="toolbar" style="display: none;">
		<table>
            <tr>
                <td>
                    <table>
                        <tr>                          
                            <td><a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'ext-icon-table_delete',plain:true" onclick="delFun();">删除</a></td>
                        </tr>
                    </table>
                </td>
            </tr>		
			<tr>
				<td>
					<form id="searchForm">
						<table>
							<tr>
								<td>活动名称：</td>
								<td>
									<input type="text" class="easyui-textbox" name="name" style="width: 150px"  />
								</td>
								<td>
									<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'ext-icon-zoom',plain:true" onclick="grid.datagrid('load',sy.serializeObject($('#searchForm')));">过滤</a>
									<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'ext-icon-zoom_out',plain:true" onclick="$('#searchForm input').val('');grid.datagrid('load',{});">重置过滤</a>
								</td>
							</tr>
						</table>
					</form>
				</td>
			</tr>
		</table>
	</div>
	<div data-options="region:'center',fit:true,border:false">
		<table id="grid" data-options="fit:true,border:false"></table>
	</div>
</body>
</html>